<!-- ************************************************************************************************************ -->
<!-- fileName          : EditTopguideFather.jsp																	  -->
<!-- author            : 马文军 																					  --> 
<!-- createDate        : 2015/01/06 																			  -->
<!-- summary           : admin端  “顶部导航” 相关编辑 --指定标签（根目录）编辑											  		  -->
<!-- modifiedBy        : 马文军																				      -->
<!-- ************************************************************************************************************ -->

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>EditTopguideFather</title>
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../js/validator.js"></script>
<script type="text/javascript">
$.ajaxSetup ({
   	cache: false //关闭AJAX相应的缓存
});
</script>
<style type="text/css">
body{
background-image:url(../../image/admin_bg.png);
background-repeat:repeat-x;
margin-left: 0px;
margin-top: 0px;
margin-right: 1px;
margin-bottom: 0px;
font-family:Microsoft YaHei;
}

h2{
font-family:Microsoft YaHei;
color:#fff;
margin: 5px 5px 5px 5px;
font-size:16px;
}

</style>
</head>
<body>

<%
	//设置请求的字符编码以支持中文
	request.setCharacterEncoding ("utf-8");

	//获取请求参数
	String id = request.getParameter("id");
	System.out.println("编辑topguide标签树	id="+id);
	
	//从web.xml获取全局参数
	String drv=config.getServletContext().getInitParameter("DBDriver");
	String url=config.getServletContext().getInitParameter("DBURL");
	String uid=config.getServletContext().getInitParameter("DBUser");
	String pwd=config.getServletContext().getInitParameter("DBPass");
	
	//构建SQL字符串和JDBC对象
	String strSQL1 = "SELECT * FROM immie0_immi.topguide tg WHERE tg.father_id=-1 AND id=?";	// (id, name, content_name, content, url, father_id, date)
	String strSQL2 = "SELECT * FROM immie0_immi.topguide tg WHERE tg.father_id=?";		// (id, name, content_name, content, url, father_id, date) 
	String strSQL3 = "SELECT * FROM immie0_immi.topguide tg WHERE tg.father_id=?";   	// (id, name, content_name, content, url, father_id, date)
	Connection conn = null;
	PreparedStatement pstmt = null;	
	ResultSet rs1 = null; //父节点
	ResultSet rs2 = null; //子节点
	ResultSet rs3 = null; //子子节点
	
	try {
		Class.forName(drv).newInstance();
		conn = DriverManager.getConnection(url,uid,pwd);
		pstmt = conn.prepareStatement(strSQL1);		
		pstmt.setString(1, id);
		
		rs1 = pstmt.executeQuery();
%>
<h2>编辑顶部导航</h2>
    
	<div id="content" style="margin:10px auto; width:600px;">
		
<% 	if(rs1.next()) { 	%>
		<div id="topguide1">
			<font>标题：</font><input type="text" disabled value=" <%=rs1.getString(2) %> " />
			
<% 			if(rs1.getString(5).equals("NULL")){ //content非空， url=NULL，内部页面		%>
				<a href="EditTopguidePage.do?id=<%=rs1.getString(1)%>">编辑此项</a>
<%			}
			if( rs1.getString(4).equals("NULL")){ //content=NULL， url非空，外部链接	 	%>			
				<a href="EditTopguideLink.do?id=<%=rs1.getString(1)%>">编辑此项</a>
<%			}	 		%>

			<a href="AddTopguidePage.do?father_id=<%=rs1.getString(1)%>&id=<%=rs1.getString(1)%>">添加子页面</a>
			<a href="AddTopguideLink.do?father_id=<%=rs1.getString(1)%>&id=<%=rs1.getString(1)%>">添加子链接</a>
		</div>
				
<%		try {
			Class.forName(drv).newInstance();
			conn = DriverManager.getConnection(url,uid,pwd);
			pstmt = conn.prepareStatement(strSQL2);
			//设置SQL语句参数
			pstmt.setString(1, rs1.getString(1) );
			
			rs2 = pstmt.executeQuery();
			
			while(rs2.next()) { 		%>
				<div id="topguide1-1" style="margin-left:50px;">
					<font>标题：</font><input type="text" disabled value=" <%=rs2.getString(2) %> " />
					
<% 					if(rs2.getString(5).equals("NULL")){ //content非空， url=NULL，内部页面		%>
						<a href="EditTopguidePage.do?id=<%=rs2.getString(1)%>">编辑此项</a>
<%					}
					if( rs2.getString(4).equals("NULL") ){ //content=NULL， url非空，外部链接	 	%>			
						<a href="EditTopguideLink.do?id=<%=rs2.getString(1)%>">编辑此项</a>
<%					}	 		%>

					<a href="DeleteTopguide.do?id=<%=rs2.getString(1)%>&father_id=<%=rs1.getString(1)%>" onClick="delcfm()">删除此项</a>
					<a href="AddTopguidePage.do?father_id=<%=rs2.getString(1)%>&id=<%=rs1.getString(1)%>">添加子页面</a>
					<a href="AddTopguideLink.do?father_id=<%=rs2.getString(1)%>&id=<%=rs1.getString(1)%>">添加子链接</a>
				</div>
				
<%				try {
					Class.forName(drv).newInstance();
					conn = DriverManager.getConnection(url,uid,pwd);
					pstmt = conn.prepareStatement(strSQL3);
					//设置SQL语句参数
					pstmt.setString(1, rs2.getString(1) );
			
					rs3 = pstmt.executeQuery();
			
					while(rs3.next()) { 		%>
						<div id="topguide1-1-1" style="margin-left:100px;">
							<font>标题：</font><input type="text" disabled value=" <%=rs3.getString(2) %> " />
							
<% 							if( rs3.getString(5).equals("NULL")){ //content非空， url=NULL，内部页面		%>
								<a href="EditTopguidePage.do?id=<%=rs3.getString(1)%>">编辑此项</a>
<%							}
							if( rs3.getString(4).equals("NULL")){ //content=NULL， url非空，外部链接	 	%>			
								<a href="EditTopguideLink.do?id=<%=rs3.getString(1)%>">编辑此项</a>
<%							}	 		%>
							
							<a href="DeleteTopguide.do?id=<%=rs3.getString(1)%>&father_id=<%=rs1.getString(1)%>" onClick="delcfm()">删除此项</a>
						</div>
<% 					}	//第三个while 结束
				}catch (ClassNotFoundException e) {
					e.printStackTrace();
				} catch (InstantiationException e) {
				    e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (SQLException e) {
					e.printStackTrace();
				} 
				finally {
					if (rs3 != null) {
						rs3.close();
						rs3 = null;
					}
				}	//第三个try 结束
			}//第二个while 结束
		}catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
		    e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		finally {
			if (rs2 != null) {
				rs2.close();
				rs2 = null;
			}
			if (rs3 != null) {
				rs3.close();
				rs3 = null;
			}
		}	//第二个try 结束
	}	//第一个if 结束
%>	
			 	
	</div>	
	
<%		
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	} catch (InstantiationException e) {
	    e.printStackTrace();
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	} catch (SQLException e) {
		e.printStackTrace();
	} 
	finally {
		if (rs1 != null) {
			rs1.close();
			rs1 = null;
		}
		if (rs2 != null) {
			rs2.close();
			rs2 = null;
		}
		if (rs3 != null) {
			rs3.close();
			rs3 = null;
		}
		if (pstmt != null) {
			pstmt.close();
			pstmt = null;
		}		
		if (conn != null) {
			conn.close();
			conn = null;
		}
	}
%>

</body>
</html>